#!/usr/bin/env python

import socket

Config = {}
Config['Server']   = 'irc.deltaanime.net'
Config['Port']     = 6667;
Config['Channel']  = '#GameDev'
Config['Nickname'] = 'DarkVoyage'
Config['Username'] = 'darkvoyage'
Config['Hostname'] = 'irc.darkvoyage.net'
Config['Realname'] = 'DarkVoyage IRC'
Config['Version']  = 'DarkVoyage IRC (/svn/trunk) -- http://code.google.com/p/darkvoyage/source/browse/trunk/irc.py'

irc = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
irc.connect((Config['Server'],Config['Port']))
irc.send('NICK '+Config['Nickname']+"\r\n")
irc.send('USER '+Config['Username']+' '+Config['Hostname']+' '+Config['Hostname']+' :'+Config['Realname']+"\r\n")
irc.send('JOIN '+Config['Channel']+"\r\n")
irc.send('PRIVMSG '+Config['Channel']+" DarkVoyage, Standalone IRC Bot -- Online\r\n")
while True:
    data = irc.recv(4096)
    if data.find('PING') != -1:
        irc.send('PONG '+data.split()[1] + "\r\n")
    elif data.find('PRIVMSG') != -1:
	nick = data.split('!')[0].replace(':','')
	message = ':'.join(data.split(':')[2:])
	location = ''.join(data.split(':')[:2]).split(' ')[-2]
	if location == Config['Nickname']:
	    location = 'PRIVATE'
	    if message.upper().find('VERSION') != -1:
		irc.send('PRIVMSG '+nick+' '+Config['Version']+"\r\n")
	print '(',location,')',nick+':',message
#irc.send("QUIT\r\n")
#irc.close()